import { Tween, Vec2, Node, tween } from "cc";

export class TweenUtil {
    // 延时触发
    public static delayCall(parent: Node, dt: number, cb: Function): Tween<Node> {
        const node: Node = new Node();
        parent.addChild(node);

        Tween.stopAllByTarget(node);
        return tween(node).delay(dt).call(() => {
            cb && cb();
            node.destroy();
        }).start();
    }

    public static async delayCallAsync(parent: Node, dt: number): Promise<void> {
        return new Promise<void>((resolve) => {
            this.delayCall(parent, dt, () => {
                resolve();
            });
        });
    }
}